#include <stdio.h>
#include <signal.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <stdlib.h>
#include <linux/types.h>
#include <linux/videodev2.h>
#include <malloc.h>
#include <math.h>
#include <string.h>
#include <sys/mman.h>
#include <errno.h>
#include <assert.h>
#include <string.h>
#include <string>
#include <sys/time.h>
#include <linux/fb.h>

#include <time.h>
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
typedef struct
{
    void *start;
    int length;
}BUFTYPE;
class camera_device
{
private:
	string video_device;
	unsigned int image_width;
	unsigned int image_height;
	unsigned char buffer_count;
	unsigned int image_size;
	int camera_device_fd;
	char *camera_image_buf;            //yuv 数据的缓存
	unsigned char *camera_rgb_buf;     //rgb数据的缓存数组
	struct v4l2_format my_v4l2_format;
	BUFTYPE *user_buf;
private:
	int clip(int value, int min, int max);
	void yum2rgb(void *data);
public:
	camera_device(){}
	camera_device(string video_device_,unsigned int image_width_,unsigned int image_height_,int buffer_count_,struct v4l2_format format);
	~camera_device();
public:
	int camera_open();
	int camera_close();
	int camera_select(int index);
	int camera_init();
	int camera_mmap_init();
	void camera_capture_start();
	void camera_capture_stop();
	int  camera_read_frame();
	void get_camera_image_data(char *data);
	void get_camera_image_data(unsigned char *data);
	void get_camera_rgb_data(unsigned char *data);
	void get_camera_yuv_data(unsigned char *data);
	void get_camera_yuv_data(char *data);
};